package cn.itsource.org.controller;

import cn.itsource.basic.util.AjaxResult;
import cn.itsource.config.exception.CustomException;
import cn.itsource.org.Dto.LoginDto;
import cn.itsource.org.service.IEmployeeService;
import cn.itsource.org.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录控制
 */
@RestController
@RequestMapping("/backLogin") //公共路径
public class LoginController {
//    注入依赖
    @Autowired
    private IEmployeeService employeeService;
    @Autowired
    private IUserService userService;
    @PostMapping("/login")  //定义后台登录的接口地址
    public AjaxResult login(@RequestBody LoginDto dto){
        try {
            return employeeService.loginCheck(dto);
        } catch (CustomException e) {
            e.printStackTrace();
            return AjaxResult.createError(e.getMessage());
        }
    }

    /**
     * 用户系统登录
     * @param loginDto
     * @return
     */
    @PostMapping("/user/login")
    public AjaxResult userLogin(@RequestBody LoginDto loginDto){
        //登录业务
        return userService.login(loginDto);
    }
}
